package com.wlz.loadBalance;

import com.wlz.ip.ServerIps;

/**
 * @author： wlz
 * @Date 2020/11/20 13:44
 * @description： TODO 轮询算法
 * @version: 1.0
 */
public class RoundRobinLoadBalance {

    private static Integer pos = 0;

    public static String getServer() {
        String ip = null;

        synchronized (pos) {
            if (pos >= ServerIps.LIST.size()) {
                pos = 0;
            }
            ip = ServerIps.LIST.get(pos);
            pos++;
        }
        return ip;
    }


    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            System.out.println(getServer());
        }
    }
}
